/**
 * Created by lenovo on 2017/5/12.
 */
import React from 'react';

class CommodityMessageDetails extends React.Component{

    getCommodityPriceOriginal(commodity){
        if(commodity.price1 !== undefined){
            const commodityPriceOriginal = parseInt(commodity.price1);
            return(
                <span className="commodityPriceOriginal">￥ {commodityPriceOriginal}</span>
            );
        }else{
            return(
                <span></span>
            );
        }
    }

    render() {
        const commodity = this.props.commodityData;
        // {
        //     id: "3437",
        //         sku: "547028241676",
        //     url: "http://test.fashioncomment.maixiang.mobi/547028241676.html",
        //     name: "ZARA·迷彩外套",
        //     price: "599.0000",
        //     image: url3
        // }

        let pic='',//商品图片
            picHref='',//商品链接
            commodityLogo='',//商品品牌
            commodityName='',//商品名称
            priceCost='',//商品现在价格
            commodityPriceOriginal='';//商品原价

        if(commodity !== [] && commodity!==undefined){
            try{
                pic = commodity.image;
                picHref = commodity.url;
                commodityLogo = commodity.name.split('·')[0];
                commodityName = commodity.name.split('·')[1];
                // (isNaN(parseInt(commodity.price)))?priceCost=0:priceCost=parseInt(commodity.price);
                priceCost=parseInt(commodity.price);
                commodityPriceOriginal = this.getCommodityPriceOriginal(commodity);
            }catch(error){
                console.log('mx_test:'+error);
            }


            return(
                <div className="commodityMessageContainer">
                    <a className="commodityLink" href={picHref}>
                        <img className="commodityPic" src={pic} />
                    </a>
                    <div className="commodityMessage">
                        <span className="commodityLogo">{commodityLogo}</span>
                        <span className="commodityName">{commodityName}</span>
                        <div className="commodityPrice">
                            <span className="commodityPriceCost">￥ {priceCost}</span>
                            {commodityPriceOriginal}
                        </div>
                    </div>
                </div>
            );
        }


    }
}

export default CommodityMessageDetails;